# coding : utf-8
# 读取json文件
import json
import os

from utils.logging_util import Log
from utils.path_util import data_path


class UtilJson:
    def __init__(self):
        # 拼接读取文件的完整路径 os.sep 获取动态路径
        self.__filepath = data_path + os.sep + 'mqttpayload.json'

    # 获取具体json文件的内容，转换为字典格式
    def get_value(self, key):
        """

        :param key: 键
        :return: 字典格式文件内容
        """
        try:
            with open(self.__filepath, 'r', encoding='utf-8') as f:
                data = json.load(f)[key]
            return data
        except Exception as e:
            Log().error(f"读取json文件错误{e}")
    def get_context(self):
        with open(self.__filepath, 'r', encoding='utf-8') as f:
            data = json.load(f)
        return data
